@media (prefers-color-scheme: dark) {
    :host {
        filter: invert(.9) hue-rotate(.5turn);
    }
}

:host {
    --window-resize: both;
    --window-min-width: 320px;
    --window-min-height: 240px;
    --window-bg-color: #fafafa;
    --content-area-padding: .3em;
    --titlebar-border-color: rgba(150, 162, 170, 0.2);
    --titlebar-bg-color: #fafafa;
    --titlebar-text-color: #334e68;
    --button-hover-bg: #e0e6ed;
    --close-button-hover-bg: #ff4d4f;
    --close-button-text-color: #666666;
    --close-button-hover-text-color: #ffffff;
    --border-radius: 10px;
    --box-shadow: 2px 2px 4px #dbdbdb, -2px -2px 4px #dbdbdb;
    --font-family: "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    --title-font-size: 1.1rem;
    --button-icon-size: 1.1rem;
    --button-gap: 0;
    --animation-duration: 0.2s;

    position: fixed;
    display: flex;
    flex-direction: column;
    min-width: var(--window-min-width);
    min-height: var(--window-min-height);
    background-color: var(--window-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    font-family: var(--font-family);
    z-index: 9999;
    resize: var(--window-resize);
    transition: box-shadow 0.3s ease-in-out, transform 0.1s ease-out;
}

@keyframes showWindow {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes hideWindow {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
}

:host(.showing) {
    animation: showWindow var(--animation-duration) ease-out forwards;
    display: flex !important;
}

:host(.hiding) {
    animation: hideWindow var(--animation-duration) ease-in forwards;
}

.content-area {
    padding: var(--content-area-padding);
    flex-grow: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--titlebar-bg-color);
    border-bottom: 1px solid var(--titlebar-border-color);
    user-select: none;
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
    flex-shrink: 0;
    cursor: grab;
}

.title-bar.dragging {
    cursor: grabbing;
}

.title-name {
    flex-grow: 1;
    font-weight: 600;
    color: var(--titlebar-text-color);
    font-size: var(--title-font-size);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    line-height: 1.4;
}

.title-buttons {
    display: flex;
    gap: var(--button-gap);
    align-items: center;
    flex-shrink: 0;
}

.title-buttons .button {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    height: 28px;
    width: 28px;
    background: none;
    font-size: var(--button-icon-size);
    cursor: default;
    border-radius: 5px;
    transition: background-color 0.2s ease, color 0.2s ease;
    color: var(--close-button-text-color);
}

.title-buttons .button:hover {
    background-color: var(--button-hover-bg);
}

.title-buttons .button::after {
    content: attr(data-hint);
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 6px 10px;
    border-radius: 5px;
    white-space: nowrap;
    font-size: 0.75rem;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, bottom 0.2s ease, visibility 0.2s ease;
    z-index: 10000;
}

.title-buttons .button:not([data-hint])::after,
.title-buttons .button[data-hint=""]::after {
    content: none;
    visibility: hidden;
    opacity: 0;
}

.title-buttons .button:hover::after {
    opacity: 1;
    bottom: -28px;
    visibility: visible;
}

.title-buttons .button[data-action="close"] {
    color: var(--close-button-text-color);
}

.title-buttons .button[data-action="close"]:hover {
    background-color: var(--close-button-hover-bg);
    color: var(--close-button-hover-text-color);
}
